A Central Processing Unit (CPU), “microprocessor” for short, is a core unit of a computer. The instruction set and design code (system architecture) adopted by a microprocessor are the primary characteristics of a computer, and they determine the types of the peripheral equipment and application software that a computer needs to use.
At present, there are two popular processor system architectures in the world: one is the Reduced Instruction Set Computing (RISC) processor system architecture represented by the MIPS32/64 Instruction Set of MIPS Technologies, Inc., and the other is the Complex Instruction Set Computing (CISC) processor system architecture represented by X86 of Intel Corporation. The CISC processor involves a huge number of instructions, some of which can execute functions quite complicated and generally need many clock periods to execute them whereas the RISC processor uses a relatively small quantity of available instructions to execute a group of simpler functions at a higher speed. The program software running on a processor adopting a different system architecture needs to be written according to the system architecture of the processor, and the application software running on X86 usually cannot run on a computer having a MIPS Instruction Set-based RISC processor, i.e., they are incompatible as what's always said.
However, computer manufacturers expect to save on costs of software development by running more existing software on a microprocessor of a system architecture manufactured by themselves and, meanwhile, to attain the object of maximizing their market shares.
In order to solve this problem, virtual machines emerge as the times require. Generally, a CPU computer having a single type of system architecture is called a host; meanwhile, a CPU environment of an unrelated system architecture type, which needs to be emulated by the host, is called an object machine, and an application program, which can spur the host to execute one or more host instructions to run the software coded for the object machine in response to the given object machine instruction, is needed and is called a virtual machine.
Virtual machines existing currently include SimOS, Quick Emulator (QEMU), Transmeta and so on. But, the existing virtual machines cost too much overhead and have a too low execution efficiency when they are running because of tremendous differences among various system architectures, so it's very difficult to apply them to practical operations.
Since the X86 processor system architecture is an architecture type popularly used in personal computers (PCs) now, most of virtual machines take the X86 processor system architecture as the object machine so that all of them need to solve the problem of being compatible with the X86 processor, and the knotty problem known to all is to emulate the unique floating-point stack mechanism of the X86 processor. Generally, a floating-point register stack is provided in a CISC processor, such as X86, and the majority of floating-point operations are performed with the participation of a register stack. Except the X86 processor, other processors, especially the MIPS Instruction Set-based RISC processor, don't have a similar architecture. Accordingly, the hot problem urgently to be solved by numerous virtual machine research and development departments is how to carry out floating-point translation on a virtual machine.
The floating-point operations of the X86 processor provide stack push (floating-point loading instruction), stack pop (floating-point storing instruction), floating-point operation instruction, and some other assistant instructions. A program may push the floating-point data of a memory into a floating-point register stack through the floating-point loading instruction, perform an operation on the floating-point data through the floating-point operation instruction, carry out stack pop through the floating-point storing instruction, and store the content of a top-of-stack register in a memory cell.
Such floating-point operation manner is unique to the CISC processor, such as the X86 processor. Processors of other types, such as the MIPS Instruction Set-based RISC processor, substantially don't have a similar operation manner.
Generally speaking, several general floating-point registers are provided within a non-CISC processor, such as the MIPS Instruction Set-based RISC processor, these floating-point registers are numbered in a unified way, an instruction directly access a fixed floating-point register via these numbers. However, in the X86 processor, the register operated by the instruction changes as a top-of-stack pointer changes. Generally, the non-CISC processor, such as the RISC processor, needs to clear a space within the memory to maintain a emulated X86 floating-point register stack, in order to solve the problem of binary data translation.
Chinese application NO. 200410074532.6 discloses a method of processing floating-point operations in X86 in binary translation, comprising: arranging a floating-point stack in the running environment for emulating the physical floating-point stack in X86; and processing every basic block in a source binary program in sequence through the processing of floating-point register mapping and the normalization method. By way of mapping the source register of X86 using registers of the object machine, it is ensured that the floating-point operation of the X86 processor is also performed by registers on the object machine, thereby ensuring the operation efficiency; meanwhile, by means of the normalization method, it is ensured that the inlet of every basic block satisfies the hypothesis that the value of top every time is the same.
Although all kinds of X86 floating-point operations can be emulated correctly in the prior art, the efficiency is too low to make progress in performance.